package canhcuadaihoc.tracnghiemonline;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class LessonDetails extends Activity{
	static boolean _chk_bookmark=false;
	static boolean _chk_like=false;
	
	Button bt_back,bt_like;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lessonpage_details);
		
		
        bt_like=(Button)findViewById(R.id.bt_like);
        bt_back=(Button)findViewById(R.id.bt_back_main_tab);
        
        //Xử lí lệnh Like
        bt_like.setOnClickListener(LikeorUnlike);
        
        //Xử lý lện quay lại trang trước
        bt_back.setOnClickListener(BackMainTab);
	}
	
	//Tạo menu hiển thị tính năng đánh dấu
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	// TODO Auto-generated method stub
    	menu.add(0, 0, 0, "Bookmark").setIcon(R.drawable.ratingimportant);
    	menu.add(0, 1, 0, "Unbookmark").setIcon(R.drawable.ratingnotimportant);
    	return super.onCreateOptionsMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	// TODO Auto-generated method stub
    	switch (item.getItemId()) {
		case 0:
			if(_chk_bookmark==true){
				Toast.makeText(this.getApplicationContext(), "Đã đánh dấu trước đó", Toast.LENGTH_SHORT).show();	
			}
			else
			{
				_chk_bookmark=true;
				Toast.makeText(this.getApplicationContext(), "Đã đánh dấu", Toast.LENGTH_SHORT).show();
			}
				
			break;
		case 1:
			if(_chk_bookmark==true)
			{
				Toast.makeText(this.getApplicationContext(), "Đã gỡ đánh dấu", Toast.LENGTH_SHORT).show();
				_chk_bookmark=false;
			}
			else
			{
				Toast.makeText(this.getApplicationContext(), "Bạn chưa đánh dấu trước đó", Toast.LENGTH_SHORT).show();
			}
		default:
			break;
		}
    	return super.onOptionsItemSelected(item);
    }
    
    View.OnClickListener BackMainTab=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			finish();
		}
	};
	View.OnClickListener LikeorUnlike=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			if(_chk_like==true)
			{
				Toast.makeText(getApplicationContext(), "UnLiked", Toast.LENGTH_SHORT).show();
				_chk_like=false;
				bt_like.setBackgroundResource(R.drawable.ratinggood);
			}
			else
			{
				Toast.makeText(getApplicationContext(), "Liked", Toast.LENGTH_SHORT).show();
				_chk_like=true;
				bt_like.setBackgroundResource(R.drawable.ratingbad);
			}
		}
	};
}
